<template>
  <div class="GetParentVs-page">
    <!-- 搜索区域 -->
    <SelfAdaption>
      <Form
        :model="formSearch"
        ref="vsForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <!-- 值集编码 -->
        <Form-item prop="vsCode" :label="$t('module.valueSet.vsCode')">
          <Input
            type="text"
            v-model="formSearch.vsCode"
            :placeholder="$t('module.valueSet.enterVsCode')"
            @on-enter="searchValueSet"
          ></Input>
        </Form-item>
        <!-- 值集名称 -->
        <Form-item prop="vsName" :label="$t('module.valueSet.vsName')">
          <Input
            type="text"
            v-model="formSearch.vsName"
            :placeholder="$t('module.valueSet.enterVsName')"
            @on-enter="searchValueSet"
          ></Input>
        </Form-item>

        <!-- 查询\重置按钮 -->
        <Form-item prop="button" class="search-solt-btn">  
          <RPButton optType="search" @click="searchValueSet" />
          <RPButton optType="reset" @click="resetValueSet" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="valueSetTable" :config="pageTableConfig">
      <!--
      <div slot="handle-bar">
        <RPButton optType="search" @click="searchValueSet" />
        <RPButton optType="reset" @click="resetValueSet" />
      </div>
      -->
    </InnerPageTable>
  </div>
</template>
<script>
import valueSet from "@lang/modules/valueSet";
export default {
  components: {},
  locales: {
    "zh-CN": {
      module: {
        valueSet: valueSet["zh-CN"]
      }
    },
    "en-US": {
      module: {
        valueSet: valueSet["en-US"]
      }
    }
  },
  data() {
    return {
      formSearch: {
        vsCode: "",
        vsName: "",
      },
      pageTableConfig: {
        highlightRow: true,
        autoFirst: true,
        loadDataFn: this.GetValueSetList,
        columns: [
          {
            title: this.$t("module.valueSet.vsCode"),
             align: "left",
            key: "vsCode"
          },
          {
            title: this.$t("module.valueSet.vsName"),
             align: "left",
            key: "vsName"
          },
          {
            title: this.$t("module.valueSet.vsType"),
             align: "left",
            key: "vsType",
            render: (h, params) => {
              return h(
                "span",
                params.row.vsType == "1"
                  ? this.$t("module.valueSet.independent")
                  : this.$t("module.valueSet.subordinate")
              );
            }
          },
          {
            title: this.$t("module.valueSet.vsValueSource"),
             align: "left",
            key: "vsValueSource",
            render: (h, params) => {
              return h("span", this.getValueSourceName(params.row.vsValueSource));
            }
          },
          {
            title: this.$t("module.valueSet.affiliation"),
             align: "left",
            key: "orgName"
          },
          {
            title: this.$t("common.status"),
             align: "left",
            key: "enabled",
            render: (h, params) => {
              return h(
                "StatusButton",
                {
                  props: {
                    status: params.row.enabled == 1 ? "0" : "1"
                  }
                },
                params.row.enabled == 1 ? this.$t("common.enable") : this.$t("common.disable")
              );
            }
          }
        ]
      }
    };
  },
  computed: {},
  created: function() {
    this.$emit("SetTitle", this.$t("module.valueSet.selectParentVs"));
    this.$emit("SetPageWidth", 894);
    this.$emit("SetPageActions", [
      {
        text: this.$t("common.confirm"),
        theme: "primary",
        icon: "ok",
        handle: this.selectParentVs
      },
      {
        text: this.$t("common.close"),
        theme: "primary",
        handle: () => {
          this.$emit("Close");
        }
      }
    ]);
  },
  beforeMount: function() {},
  mounted: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    GetValueSetList({ responseProcess, param }) {
      console.log('param',param);
      param.condition.enabled = 1 ;
      param.condition.vsType = 1;
      $http.post(`${window.RPConfig.setting}/valueset/list/page`, param).then(response => {
        responseProcess(response.data);
      });
    },
    selectParentVs() {
      let currentRow = this.$refs["valueSetTable"].getHighlightRow();
      if (currentRow && currentRow.vsCode) {
        let obj = { vsCode: currentRow.vsCode, vsName: currentRow.vsName };
        this.$emit("Close", obj);
      } else {
        this.$message.error({
          content: this.$t("module.valueSet.selectAffiliation"),
          duration: 3
        });
        return;
      }
    },
    cancel() {
      this.$emit("Close");
    },
    searchValueSet() {
      this.$refs["valueSetTable"].load(this.formSearch);
    },
    resetValueSet() {
      this.$refs["vsForm"].resetFields();
      this.$refs["valueSetTable"].load(this.formSearch);
    },
    getValueSourceName(key) {
      if (key == 1) {
        return this.$t("module.valueSet.valueSourceItem.system");
      } else if (key == 2) {
        return this.$t("module.valueSet.valueSourceItem.scalable");
      } else if (key == 3) {
        return this.$t("module.valueSet.valueSourceItem.custom");
      } else if (key == 4) {
         return this.$t("module.valueSet.valueSourceItem.dynamic");
      }
      return key;
    }
  },
  watch: {},
  directives: {}
};
</script>
<style lang="less">
// ok统一注释的样式
.GetParentVs-page {
//   .run-search-bar>div:last-child {
//       margin-top: 10px!important;
//   }
  .self-adaption-wrap{
    margin: 0 -10px;
  }
  .single-table-con{
    padding: 0;
    .table-bar{
      display: none;
    }
  }
}
</style>